import { BULLET_SPEED } from '../../../config/play_def';
import debullet from '../../base/debullet'
cc.Class({
    extends: debullet,

    properties: {
    },
    initInfo(param){
        this.script_name = `mon_bullet`    // 脚本名赋值 必填！
        this.order_line = param.order_line
        this.fin_pos = this.node.parent.convertToNodeSpaceAR(param.fin_pos)
        this.dir = param.dir
        this._super(param)
    },
    clearInfo(){
        this.fin_pos = cc.Vec2.Zero
        this._super()
    },
    turnDir(){
        let t = this.dir.signAngle(cc.v2(1,0));
        if(t){
            var degree = t / Math.PI * 180 + 90;
            while (Math.abs(degree) > 360) {
                if(degree < 0){
                    degree += 360
                }else{
                    degree -= 360
                }
            }
            if(degree < 0){
                degree = 360 + degree
            }    
            this.node.angle = -degree
        }
    },
    fly(dt){
        this._super(dt)
        let target = this.dir.mul(this.speed * BULLET_SPEED * dt)

        this.node.position = target.add(this.node.position)
        if(this.node.y < this.fin_pos.y + 100){
            this.attack()
        }
    }
});
